package com.ostsm.advmainapplication.Receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.ostms.adv.BuildConfig;
import com.ostms.adv.activity.FaceDetectActivity;
import com.ostms.adv.utils.LOG;

import java.util.Timer;
import java.util.TimerTask;


public class StartUpReceiver extends BroadcastReceiver {

    private static final String TAG = "StartUpReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
                final Context mContext = context;
                LOG.i("StartUpReceiver.onReceive", "开机广播");
                final Intent mainIntent = new Intent(mContext, FaceDetectActivity.class);
                mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if("qingwa".equals(BuildConfig.TARGET_CUSTOMER)){
                    TimerTask task = new TimerTask(){
                        public void run(){
                            LOG.i(TAG,"start ADV apk!");
                            mContext.startActivity(mainIntent);
                        }
                    };
                    Timer timer = new Timer();
                    //10秒后执行
                    timer.schedule(task, 10 * 1000);
                }else{
                    mContext.startActivity(mainIntent);
                }
            }
        } catch (Throwable e) {
        }
    }
}
